<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .ad {
            width: 200px;
            height: 200px;
            background-color: #aaa;
            position: fixed;
            right: 0;
            bottom: 0;
            padding-left: 20px;

            display: none;
        }
        .close {
            float: right;
            width: 20px;
            height: 20px;
            text-align: center;
            line-height: 20px;
            background-color: #000;
            color: #fff;
            cursor: pointer;
        }
    </style>
</head>
<body>

    <div id="ad" class="ad">
        <span id="c" class="close">X</span>
        <p id="showTime">10s之后关闭</p>
        <h3>我是小广告，请联系我</h3>
    </div>

    <script>

        // 获取这个标签
        var oAd = document.getElementById('ad') ;
        var oClose = document.getElementById('c') ;
        var oTime = document.getElementById('showTime') ;

        // 页面打开3s之后弹出小广告
        setTimeout(function(){
            oAd.style.display = 'block' ;


            // 点X关闭
            oClose.onclick = function() {
                oAd.style.display = 'none' ;
                // 也要清除定时器 。。。
            }


            // 10s倒计时之后，也会自动关闭
            var count = 10 ;
            var t = setInterval(function(){
                count-- ;
                // 把count显示在标签里面
                oTime.innerHTML = count + 's之后自动关闭';
                // 判断到0就要关闭
                if(count <= 0) {
                    oAd.style.display = 'none' ;
                    // 需要清除一下定时器
                    clearInterval(t);
                }
            } , 1000)

        } , 3000)

    </script>
    
</body>
</html>